from common import data_check


def SMS_wan_qurey(args):
    parameter_list = list(args.strip().split())
    print(parameter_list)
    print(len(parameter_list))
    if not len(parameter_list):
        return ""
    if len(parameter_list) > 1:
        return '只能输入一个手机号码'

    data_check_result = data_check(parameter_list, 1, 1, 'phone')
    if not data_check_result[0]:
        return f"数据格式错误，{data_check_result[1]}不是手机号码"

    parameter_str = str(parameter_list).replace('[', '').replace(']', '').replace("\'", '')

    result = f'cat /opt/forenet/bin/dpsgowan/dps/log.log |grep -a $(date +%Y/%m/%d) |grep -a {parameter_str}'
    return result

def SMS_qurey(args):
    parameter_list = list(args.strip().split())
    print(parameter_list)
    print(len(parameter_list))
    if not len(parameter_list):
        return ""
    if len(parameter_list) > 1:
        return '只能输入一个手机号码'

    data_check_result = data_check(parameter_list, 1, 1, 'phone')
    if not data_check_result[0]:
        return f"数据格式错误，{data_check_result[1]}不是手机号码"

    parameter_str = str(parameter_list).replace('[', '').replace(']', '').replace("\'", '')

    result = f'cat /opt/forenet/bin/dpsgo/dps/log.log |grep -a $(date +%Y/%m/%d) |grep -a {parameter_str}'
    return result


def different_mailbox_OA(args):
    parameter_list = list(args.strip().split())
    print(parameter_list)
    print(len(parameter_list))
    if not len(parameter_list):
        return ""

    if len(parameter_list) > 1:
        return '只能输入一个用户名'
    parameter_str = str(parameter_list).replace('[', '').replace(']', '').replace("\'", '')
    result = ''
    result += '--查询邮箱\n'
    result += f"select  *  from  uap_app_acct  where  login_acct='{parameter_str}' and app_id='63';\n"
    result += '--修改为OA邮箱\n'
    result += f"update  uap_app_acct a set  email='{parameter_str}@zj.chinamobile.com' where login_acct='{parameter_str}' and app_id='63';"

    return result


def different_mailbox_other(args):
    parameter_list = list(args.strip().split())
    print(parameter_list)
    print(len(parameter_list))
    if not len(parameter_list):
        return ""

    if len(parameter_list) != 2:
        return '请输入一个用户名和一个邮箱'

    data_check_result = data_check(parameter_list, 2, 2, 'mail')
    if not data_check_result[0]:
        return f"数据格式错误，{data_check_result[1]}不是邮箱"

    parameter_username = str(parameter_list[0]).replace('[', '').replace(']', '').replace("\'", '')
    parameter_mail = str(parameter_list[1]).replace('[', '').replace(']', '').replace("\'", '')
    result = ''
    result += '--查询邮箱\n'
    result += f"select * from uap_app_acct where login_acct='{parameter_username}' and app_id='63';\n"
    result += '--修改为其他邮箱\n'
    result += f"update uap_app_acct a set email='{parameter_mail}' where login_acct='{parameter_username}' and app_id='63';"

    return result


def no_current_user(args):
    parameter_list = list(args.strip().split())
    print(parameter_list)
    print(len(parameter_list))
    if not len(parameter_list):
        return ""

    if len(parameter_list) > 1:
        return '只能输入一个用户名'
    parameter_str = str(parameter_list).replace('[', '').replace(']', '').replace("\'", '')
    result = ''
    result += '--查询用户attribute1\n'
    result += f"select username,description,userid,attribute1 from ums_user where description = '{parameter_str}';\n"
    result += '--更新attribute1\n'
    result += f"update ums_user set attribute1='10108437' where description = '{parameter_str}';\n\n"

    result += '--查询用户opid\n'
    result += f"select * from uums_sys_account_info_view a where a.USERID ='{parameter_str}' and a.SYSKEY='F8WW';"

    return result


def demo(args):
    parameter_list = list(args.strip().split())
    print(parameter_list)
    print(len(parameter_list))
    if not len(parameter_list):
        return ""

    result = ''
    return result
